﻿CREATE PROCEDURE [dbo].[UpdateMark]
	@MarkId uniqueidentifier,
    @ResponsibleParticipant uniqueidentifier,
    @NextParticipant uniqueidentifier,
	@Activity uniqueidentifier,
	@Model uniqueidentifier,
    @Name nvarchar(max),
	@Tag nvarchar(max),
	@DueDate datetime,
    @Weight int,
    @IsActive bit,
    @DateSet datetime,
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE Mark

	SET 
	 
     ResponsibleParticipant = @ResponsibleParticipant,
     NextParticipant = @NextParticipant,
	 Activity = @Activity,
	 Model = @Model,
     Name = @Name,
	 Tag = @Tag,
	 DueDate = @DueDate,
     [Weight] = @Weight,
     IsActive = @IsActive,
     DateSet = @DateSet,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
 	 LastChangedBy = @LastChangedBy

	WHERE MarkId = @MarkId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM Mark 

	WHERE Markid = @MarkId

RETURN 0